<?php

class status_StatusController extends Zend_Controller_Action
{
  function init() {
  	$this->view->headLink()->appendStylesheet($this->view->baseUrl().'/ressources/status/style.css');
  }
  
  //publish a status for the user
  function publishAction() {
    //We get the status of the user
	$status = $this->_getParam('status');
	$engine = Myzen_Oauth_Query_Singleton::getInstance();    
    $data = $engine->query('status','statuses','create',array('status' => $status));
	$result = unserialize($data);
	if($result['status'] == 'OK') $this->view->messageDisplay()->setMessage('Message added','confirmation');
	else echo $this->view->messageDisplay()->setMessage($result['error']['message'],'error');
	$this->_forward('index','index');
	
	
  } //end publishAction


  function displayAction() {
  	$id = $this->_getParam('id');
  	
	$engine = Myzen_Oauth_Query_Singleton::getInstance(); 
    $data = $engine->query('status','statuses','read',array('id' => $id));
	$result = unserialize($data);  	
	

	//we get the avatar base URL
	$this->view->avatarBaseURL = Zend_Registry::get('app_config')->avatar->baseURL;
	
	$this->view->status = $result['data'];

	//we provide the authenticated user id to check if he can delete the status
	$this->view->userId = Zend_Registry::get('app_session')->userDetails['id'];
		
  }
  
  
  function deleteAction() {
  	$id = $this->_getParam('id');
  	
	$engine = Myzen_Oauth_Query_Singleton::getInstance(); 
    $data = $engine->query('status','statuses','delete',array('id' => $id));
	$result = unserialize($data);
	
	if($result['status'] == 'OK') $this->view->messageDisplay()->setMessage('Message deleted','confirmation');
	else echo $this->view->messageDisplay()->setMessage($result['error']['message'],'error');
	
	$this->_forward('index','index');
		
  }

} //End class